PROJECTENGRAM

DESIGN PRINCIPLES

Design Principles

Tags: #◇Computer Science #◇CCPROG3 #◇Design Principles #◇Conceptual #◇M11


◇Key Definitions

Design Principles are guidelines that help software engineers design better, more maintainable, and scalable object-oriented software. The most prominent are the SOLID principles.

◇Theoretical Framework

SOLID is an acronym for five design principles:

  1. Single Responsibility Principle (SRP): A class should have one, and only one, reason to change.
  2. Open/Closed Principle (OCP): Software entities should be open for extension, but closed for modification.
  3. Liskov Substitution Principle (LSP): Subtypes must be substitutable for their base types without altering the correctness of the program.
  4. Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use.
  5. Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules. Both should depend on abstractions.

◇Important Formulas

Coupling vs. Cohesion: Good design aims for Low Coupling (dependencies between modules are minimized) and High Cohesion (responsibilities within a module are strongly related).

◇Worked Examples

Violating SRP: A User class that handles user data storage, user validation, and email notification.
Fixing SRP: Create separate classes: UserRepository (storage), UserValidator (validation), and EmailService (notification).

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

What does the Single Responsibility Principle (SRP) dictate?

Q2

According to the Open/Closed Principle (OCP), how should software entities be designed?

Q3

Which principle states that subtypes must be substitutable for their base types without altering program correctness?

Q4

What is the goal of having "High Cohesion" in software design?

Q5

How would you fix a User class that handles user data storage, validation, and email notifications to adhere to SRP?

Design Principles | PROJECT ENGRAM